/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.cheln.explorer.cpnt.adapter;

import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

import android.content.Context;
import android.database.Cursor;
import android.view.View;
import android.widget.TextView;
import cn.cheln.explorer.beans.ApkInfo;
import cn.cheln.explorer.beans.FileInfo;
import cn.cheln.explorer.beans.MusicInfo;
import cn.cheln.support.ui.DensityUtil;
import cn.cheln.support.ui.adapter.ItemDataSrc;
import cn.power.shine.R;

/**
 * 
 * @author chenliang
 */
public class CountAdapter extends FileAdapter {

	public CountAdapter(Context context, AdaptInfo listViewHolder) {
		super(context, listViewHolder);
	}

	public Map<Integer, Object> items = new TreeMap<Integer, Object>(
			new Comparator<Integer>() {

				public int compare(Integer arg0, Integer arg1) {
					return arg0 - arg1;
				}
			});

	@Override
	public Object getItem(int position) {
		if (!items.containsKey(position)) {
			items.put(position, super.getItem(position));
		}
		Object obj = items.get(position);
		if (obj == null) {
			return null;
		}
		return obj;
	}
    public void setItemDataSrc(ItemDataSrc itemDataSrc) {
        items.clear();
        super.setItemDataSrc(itemDataSrc);
    }
	Cursor cursorTmp;
    int density260 = DensityUtil.dip2px(context, 260);
    int density105 = DensityUtil.dip2px(context, 105);
    @Override
    protected void getViewInDetail(Object item, int position, View convertView) {
        super.getViewInDetail(item, position, convertView);
        View apkVersion = convertView.findViewById(R.id.fileTimeSize);
        if (apkVersion != null) {
            ((TextView) apkVersion).setMaxWidth(item instanceof ApkInfo ? density105 : density260);
        }
    }
	public FileInfo getSimpleFileItem(int pos) {
		FileInfo info = null;
		try {
			cursorTmp = ((Cursor) this.getItemDataSrc().getContent());
			cursorTmp.moveToPosition(pos);
			info = new FileInfo(cursorTmp.getString(cursorTmp
					.getColumnIndex("_data")));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return info;
	}

	@Override
	protected FileInfo getThumbnailBase(FileInfo fileInfo) {
		if (fileInfo instanceof MusicInfo) {
			if (((MusicInfo) fileInfo).thumbnail != null) {
                fileInfo.thumbnailPath = ((MusicInfo) fileInfo).thumbnail;
			}
		}
		return fileInfo;
	}
}
